package com.hunau.iot.server.common.persist;

import com.hunau.common.utils.RedisUtil;
import com.hunau.iot.server.utils.SpringContextUtils;
import com.hunau.system.domain.TbEnergy;
import com.hunau.system.domain.TbEnvironment;
import com.hunau.system.domain.TbIoterminal;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @program: ruoyi
 * @description: redis
 * @author: Mr.Liu
 * @create: 2020-03-24 11:22
 **/
public class RedisMemery implements BaseMo{

    private static RedisUtil redisUtil=(RedisUtil) SpringContextUtils.getBeanByClass(RedisUtil.class);
    @Override
    public boolean insert(Object msg) {
        if(msg instanceof TbEnvironment){
            try{
                String s = redisUtil.toJson(msg);
                redisUtil.listRightSet("iot_environment",s);
                return true;
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        if(msg instanceof TbEnergy){
            try{
                String s = redisUtil.toJson(msg);
                redisUtil.listRightSet("iot_energy",s);
                return true;
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        return false;
    }

    @Override
    public boolean update(Object msg) {
        if(msg instanceof TbIoterminal){
            try {
                String s = redisUtil.toJson(msg);
                redisUtil.listRightSet("iot_ioterminal",s);
                return true;
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        return false;
    }
}
